import { useState } from "react";
import { Upload } from "../../component";
import uploadImg from "../../assets/upload.webp";
import { message } from "antd";
function App() {
  const [url, setUrl] = useState(uploadImg);
  const customUpload = (file: File) => {
    const fileReader = new FileReader();
    fileReader.readAsDataURL(file);
    fileReader.addEventListener("load", () => {
      if (fileReader.result) {
        setUrl(fileReader.result as string);
      }
    });
  };
  const beforeUpload = (file: File) => {
    if (!file.type.includes("image")) {
      message.warning("上传的文件只可以是图片!!!!");
      return false;
    }
    return true;
  };
  return (
    <div className="App">
      <Upload upload={customUpload} beforeUpload={beforeUpload}>
        <img
          src={url}
          style={{ width: 200, height: 200, objectFit: "cover" }}
          alt=""
        />
      </Upload>
    </div>
  );
}
export default App;
